import router from './router'
import Cookies from 'js-cookie'
import { GetUserId } from '@/api/request'
router.beforeEach(async (to, from, next) => {
    // debugger
    if (Cookies.get('token2') && to.params.id) {
        next()
    } else {
        if (!to.params.id) return
        const res = await GetUserId(to.params.id)
        if (res.errCode == 0) {
            Cookies.set('token2', to.params.st)
            next({ path: `/${to.params.id}` })
        } else {
            if (to.params.id) {
                var rootUrl = ''
                if (process.env.NODE_ENV == 'development') {
                    rootUrl = process.env.VUE_APP_API_URL
                } else if (process.env.NODE_ENV == 'debug') {
                    rootUrl = ''
                } else if (process.env.NODE_ENV == 'production') {
                    rootUrl = process.env.VUE_APP_API_URL
                }
                // window.location.href = `https://olpassport.5211game.com/Login?siteid=50008&returnUrl=${escape(window.location.href)}&srvid=7`
                window.location.href = `${rootUrl}Passport/Index?returnUrl=${escape(window.location.href)}`
            } else {
                window.location = "https://www.5211game.com"
                Cookies.remove('token2')
            }

        }

    }

})